home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group00b.txt
/
000095_icon-group-sender_Tue Oct 24 08:18:24 2000.msg
< prev
next >
Wrap
Internet Message Format
|
2001-01-03
|
4KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id e9OFI8B14452
for icon-group-addresses; Tue, 24 Oct 2000 08:18:08 -0700 (MST)
Message-Id: <200010241518.e9OFI8B14452@baskerville.CS.Arizona.EDU>
From: "Jay Hammond" <J.Hammond@qmw.ac.uk>
To: icon-group@cs.arizona.edu
Date: Tue, 24 Oct 2000 10:49:48 +0000
Subject: re: simple - can't index a string
X-Confirm-Reading-To: J.Hammond@qmw.ac.uk
X-pmrqc: 1
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 3066
> Greetings:
>
> Another question that "should" be simple....but I can't seem to figure
> it out.
>
> I have the statement....
>
> UPPER[index] := &ucase[find(data[index],&lcase)]
>
> ....which is giving an error:
>
> Traceback:
> main()
> {(variable = &null)[1]} from line 8 in noname.icn
>
> best I can tell, it is choking because UPPER has not been "declared".
> But I can't find anywhere how to "declare" a string. In fact, all the
> references I find talk about how ICON doesn't NEED "declarations"
in the
> traditional sense of a programming language. Soooo...uhhh....???
Perhaps I have a solution to the first part;
First off, the bald solution:
Don't declare the string to have type "string", just create a
suitable string.
and some words of explanation;
If I may approach this problem from the side, by
thinking about what is going wrong,
suppose the INDEX to UPPER was 5
(I know your error message said it evaluated to 1)
then you'd be looking at the thing at position 5 in UPPER.
Any programming language will have a hard
time locating position 5 in a string that does not exist.
You have said that UPPER does not exist yet.
At best, you could expect a request to index into UPPER to
"default" to creating a string of ... err what would it be? Ascii nulls,
Blanks, something long enough to resolve your reference, and return the
relevant part of your default string. - so in my example you'd get the
5th blank (or whatever) along. In my opinion, it is more use to you as a
programmer to be told
There's no such string as UPPER, so it's getting you nowhere to
look at position 5 in it.
You don't have to declare UPPER before you use it, and the type,
when you do use it, will be figured out for you.
I propose
UPPER := "a suitable string for your purpose"
I have had a similar problem; I have tried
while (......) do {
i +:= 1
....
}
and wondered why I get errors incrementing i
It turns out that i had no value earlier, and unlike Snobol,
that absence of a value does not convert to a numeric zero.
I have to write
i := 0
before the loop construct,
(or whatever starting value my loop needs)
You can't increment nothing, but you can increment from zero.
You can't index into a string that's not there.
Don't declare the string, create it!
I think, if you request an index that is off the end of a string,
you just get a graceful fail, that might let you backtrack or resume. so
animal := "cat" # I just got Icon to make me a string if
animal[5] then write("cat o' nine tails") else write("manx")
should always write "manx"
(non-brits; there is a pun here
cat o' nine tails is an whip with 9 thongs (naval, historical)
a manx cat is one from the isle of man, a breed with no tail to speak of
<I hope that is not because they are docked>)
[snipped 2ndary question already answered better than I could]
all the best, Jay
Jay Hammond, Email j.hammond@qmw.ac.uk
Arts Computing Unit
Queen Mary & Westfield College,
Mile End Rd, London E1 4NS
Phone +44 20 7882 3209